package com.zyong.design.pattern.mediator.case1;

/**
 * @program: zyong-design-pattern
 * @ClassName: AbstractColleague
 * @author: zyong
 * @create: 2024-04-01 00:06
 */
public abstract class AbstractColleague implements Colleague {
    private String name;
    private Mediator mediator;

    public AbstractColleague(String name, Mediator mediator) {
        this.name = name;
        this.mediator = mediator;

        mediator.register(this);
    }

    @Override
    public void send(String message) {
        System.out.println("name = " + name + ", 发送了消息 = " + message);
        mediator.relay(this, message);
    }

    @Override
    public void receive(String message) {
        System.out.println("name = " + name + ", 接收到消息 = " + message);
    }
}
